import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;

import oracle.jdbc.pool.OracleDataSource;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class MainPage extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField satementIn;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			MainPage dialog = new MainPage();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private String accessType, query,outName, outBirthday,outPhone;
    private Connection conn;
    private ResultSet result;
    
	public void connect() throws SQLException {
        OracleDataSource ods = new OracleDataSource();
        ods.setURL("jdbc:oracle:thin:ops$mdye3/wonderLab@acme.gatech.edu:1525:public");
        conn = ods.getConnection();
    }
	public Boolean makeStatementForDatabase(String statement) throws SQLException {
		
		connect();
		query = statement;
    	PreparedStatement statementOut = conn.prepareStatement(query);
    	
        try {
			result = statementOut.executeQuery();
		} catch (SQLException e) {
            conn.close();
            statementOut.close(); 
			System.out.println(e.toString());
			return false;
		} 
		conn.close();
        statementOut.close();
        
        return true;
		
	}
	/**
	 * Create the dialog.
	 */
	public MainPage() {
		setBounds(100, 100, 590, 173);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			satementIn = new JTextField();
			satementIn.setBounds(42, 10, 499, 20);
			contentPanel.add(satementIn);
			satementIn.setColumns(10);
		}
		
		JButton btnGo = new JButton("Go!");
		btnGo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				try {
					boolean fail = makeStatementForDatabase(satementIn.getText());
					if(fail == true)
					{
						JOptionPane.showMessageDialog(contentPanel, "Success");
					}
					else
						JOptionPane.showMessageDialog(contentPanel, "False");
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		btnGo.setBounds(214, 55, 89, 23);
		contentPanel.add(btnGo);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
